<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('项目操作记录列表')" />
</head>
<body class="gray-bg">
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <i class="fa fa-list"></i> 项目操作记录
                    </h4>
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <h5 th:if="${project != null}">
                                <strong>项目：</strong>
                                <span th:text="${project.name}"></span>
                                <small th:if="${project.customerName != null and project.customerName != ''}">（<span th:text="${project.customerName}"></span>）</small>
                            </h5>
                        </div>
                    </div>
                    
                    <div class="btn-group-sm" id="toolbar" role="group">
                        <a class="btn btn-info" onclick="refreshTable()">
                            <i class="fa fa-refresh"></i> 刷新
                        </a>
                        <a class="btn btn-warning" onclick="exportData()">
                            <i class="fa fa-download"></i> 导出
                        </a>
                    </div>
                    
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />

<script th:inline="javascript">
    var prefix = ctx + "project/issueOperation";
    var projectId = [[${project.id}]];
    
    $(function() {
        var options = {
            url: prefix + "/project/list/" + projectId,
            modalName: "项目操作记录",
            columns: [{
                field: 'id',
                title: '编号',
                width: '5%'
            },
            {
                field: 'issueId',
                title: '需求ID',
                width: '8%',
                formatter: function(value, row, index) {
                    return '<a href="javascript:void(0);" onclick="openIssueDetail(' + value + ')">#' + value + '</a>';
                }
            },
            {
                field: 'operatorName',
                title: '操作人',
                width: '10%'
            },
            {
                field: 'operationDesc',
                title: '操作内容',
                width: '10%'
            },
            {
                field: 'operationTime',
                title: '操作时间',
                width: '15%',
                sortable: true,
                formatter: function(value, row, index) {
                    if (value) {
                        var date = new Date(value);
                        return date.getFullYear() + "-" + 
                               ("0" + (date.getMonth() + 1)).slice(-2) + "-" + 
                               ("0" + date.getDate()).slice(-2) + " " + 
                               ("0" + date.getHours()).slice(-2) + ":" + 
                               ("0" + date.getMinutes()).slice(-2) + ":" + 
                               ("0" + date.getSeconds()).slice(-2);
                    }
                    return "";
                }
            },
            {
                field: 'customerName',
                title: '相关客户',
                width: '15%'
            },
            {
                field: 'issueSubject',
                title: '相关需求',
                width: '25%',
                formatter: function(value, row, index) {
                    return '<a href="javascript:void(0);" onclick="openIssueDetail(' + row.issueId + ')">' + value + '</a>';
                }
            },
            {
                field: 'remarks',
                title: '备注',
                width: '12%'
            },
            {
                title: '操作',
                align: 'center',
                width: '10%',
                formatter: function(value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="viewDetail(\'' + row.id + '\')"><i class="fa fa-view"></i>查看</a> ');
                    actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="openIssueOperationRecords(\'' + row.issueId + '\')"><i class="fa fa-list"></i>相关操作</a> ');
                    return actions.join('');
                }
            }]
        };
        $.table.init(options);
    });
    
    /* 刷新表格 */
    function refreshTable() {
        $.table.refresh();
    }
    
    /* 导出数据 */
    function exportData() {
        var params = {
            projectId: projectId
        };
        $.table.exportExcel(params);
    }
    
    /* 查看需求详情 */
    function openIssueDetail(issueId) {
        var url = ctx + "project/issue/" + issueId;
        window.open(url, '_blank');
    }
    
    /* 查看操作记录详情 */
    function viewDetail(id) {
        var url = prefix + "/view/" + id;
        $.modal.openTab("操作记录详情", url);
    }
    
    /* 查看需求的所有操作记录 */
    function openIssueOperationRecords(issueId) {
        var url = prefix + "/issue/" + issueId;
        $.modal.openTab("需求操作记录", url);
    }
</script>
</body>
</html>